﻿using System;

namespace Faml.Frontend
{
    public class FamlFrontentException : ApplicationException
    {
        private Location location;
        private string innerMessage;

        public FamlFrontentException()
        {
            location = Location.Unknown;
            innerMessage = "";
        }

        public FamlFrontentException(string message) : base(message)
        {
            location = Location.Unknown;
            innerMessage = message;
        }

        public FamlFrontentException(Location location, string message)
            : base(String.Format("{0} at {1}", message, location.ToString()))
        {
            this.location = location;
            this.innerMessage = message;
        }

        public Location Location
        {
            get { return location; }
        }

        public string InnerMessage
        {
            get { return innerMessage; }
        }    
    }

    public class CompilerException : FamlFrontentException
    {
        public CompilerException(Location location, string message)
            : base(location, message)
        { /* Nothing to do here */ }
        public CompilerException(string message)
            : base(message)
        { /* Nothing to do here */ }
        public CompilerException()
            : base()
        { /* Nothing to do here */ }

        public static void Throw(string message)
        {
            throw new CompilerException(message);
        }

        public static void Throw(Location loc, string message)
        {
            throw new CompilerException(loc, message);
        }

        public static void Throw(Parser p, string message)
        {
            Throw(p.CurrentToken.Location, message);
        }
    }

}